﻿
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Windows.Forms;
using System.Net.NetworkInformation;
using System.Drawing.Drawing2D;
using System.IO;
using System.Runtime.InteropServices;
using AgvPublic;
using NPOI.SS.Formula.Functions;
using System.Threading.Tasks;
using Newtonsoft.Json;

namespace AgvDemo
{
    public delegate void CommunicateTaskShowCallBack();//跨线程操作回调函数
    public delegate void CommunicatePlcDataCallBack(string ip);//跨线程操作回调函数
    public delegate void CommunicateManagerCallBack(string ip,byte[] buffer);//跨线程操作回调函数
    //public delegate void CommunicateAgvInfoCallBack(Model.Agv_Info agvInfo, AgvFunctionClass agvFun);//跨线程操作回调函数
    public delegate void CommunicateTrafficMonitorCallBack(Dictionary<int, TrafficDetailClass> TrafficDataListTemp);//跨线程操作回调函数
    //public delegate void CommunicateAgvDataCallBack(Model.Agv_Info agvInfo,AgvFunctionClass agvFun);//跨线程操作回调函数
    //public delegate void CommunicateAgvShowCallBack(Model.Agv_Info agvInfo, AgvFunctionClass agvFun);//跨线程操作回调函数

    public delegate void CommunicateOkAgvShowCallBack(ChargeParaClass agvInfo, AgvFunctionClass agvFun);//跨线程操作回调函数

    public partial class MainForm : Form
    {
        //public static readonly log4net.ILog log = log4net.LogManager.GetLogger(typeof(MainForm));//输出日志
        string userAcc;
        string passW;
                         
        public static MainForm mainForm;
      

        public System.Windows.Forms.Timer tmOffine;
        public System.Windows.Forms.Timer tmTime;
        public System.Windows.Forms.Timer tmTrafficRecord;
        public System.Windows.Forms.Timer tmTaskShow;
        public System.Windows.Forms.Timer tmFeelTask;
        public System.Windows.Forms.Timer tmPlc;

        public System.Windows.Forms.Timer tmOkAgv;

        MainManagerClass mainManager;//逻辑起点

      
        public MainForm()
        {
            InitializeComponent();
          
            CheckForIllegalCrossThreadCalls = false;

          

            dgAgvInfo.ColumnHeadersDefaultCellStyle.Font = new Font("微软雅黑", 10.5F, System.Drawing.FontStyle.Bold);
            dgAgvInfo.DefaultCellStyle.Font = new Font("微软雅黑", 10.5F, System.Drawing.FontStyle.Bold);
            dgAgvInfo.AllowUserToAddRows = false;
            dgAgvInfo.ReadOnly = true;

            dgCheck.ColumnHeadersDefaultCellStyle.Font = new Font("微软雅黑", 12F, System.Drawing.FontStyle.Bold);
            dgCheck.DefaultCellStyle.Font = new Font("微软雅黑", 12F, System.Drawing.FontStyle.Bold);
            dgCheck.AllowUserToAddRows = false;
            dgCheck.ReadOnly = true;
            //dgCheck.CellBorderStyle = DataGridViewCellBorderStyle.Single;

            dgStation26.ColumnHeadersDefaultCellStyle.Font = new Font("微软雅黑", 12F, System.Drawing.FontStyle.Bold);
            dgStation26.DefaultCellStyle.Font = new Font("微软雅黑", 12F, System.Drawing.FontStyle.Bold);
            dgStation26.ReadOnly = true;
            dgStation26.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
            dgStation26.ForeColor = Color.Black;
            dgStation26.DefaultCellStyle.SelectionBackColor = Color.White;
            dgStation26.DefaultCellStyle.SelectionForeColor = Color.Black;

            dgFault26.ColumnHeadersDefaultCellStyle.Font = new Font("微软雅黑", 12F, System.Drawing.FontStyle.Bold);
            dgFault26.DefaultCellStyle.Font = new Font("微软雅黑", 12F, System.Drawing.FontStyle.Bold);
            dgFault26.ReadOnly = true;
            dgFault26.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
            dgFault26.ForeColor = Color.Black;
            dgFault26.DefaultCellStyle.SelectionBackColor = Color.White;
            dgFault26.DefaultCellStyle.SelectionForeColor = Color.Black;

            dgCommand26.ColumnHeadersDefaultCellStyle.Font = new Font("微软雅黑", 12F, System.Drawing.FontStyle.Bold);
            dgCommand26.DefaultCellStyle.Font = new Font("微软雅黑", 12F, System.Drawing.FontStyle.Bold);
            dgCommand26.ReadOnly = true;
            dgCommand26.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
            dgCommand26.ForeColor = Color.Black;
            dgCommand26.DefaultCellStyle.SelectionBackColor = Color.White;
            dgCommand26.DefaultCellStyle.SelectionForeColor = Color.Black;

            dgTraffic.ColumnHeadersDefaultCellStyle.Font = new Font("微软雅黑", 12F, System.Drawing.FontStyle.Bold);
            dgTraffic.DefaultCellStyle.Font = new Font("微软雅黑", 12F, System.Drawing.FontStyle.Bold);
            dgTraffic.AllowUserToAddRows = false;
            //dgTraffic.CellBorderStyle = DataGridViewCellBorderStyle.Single;

            dgLine.ColumnHeadersDefaultCellStyle.Font = new Font("微软雅黑", 12F, System.Drawing.FontStyle.Bold);
            dgLine.DefaultCellStyle.Font = new Font("微软雅黑", 12F, System.Drawing.FontStyle.Bold);
            dgLine.AllowUserToAddRows = false;
            //dgLine.CellBorderStyle = DataGridViewCellBorderStyle.Single;

            dgFang.ColumnHeadersDefaultCellStyle.Font = new Font("微软雅黑", 12F, System.Drawing.FontStyle.Bold);
            dgFang.DefaultCellStyle.Font = new Font("微软雅黑", 12F, System.Drawing.FontStyle.Bold);
            dgFang.AllowUserToAddRows = false;
            dgFang.ReadOnly = true;

            dgLocation.ColumnHeadersDefaultCellStyle.Font = new Font("微软雅黑", 12F, System.Drawing.FontStyle.Bold);
            dgLocation.DefaultCellStyle.Font = new Font("微软雅黑", 12F, System.Drawing.FontStyle.Bold);
            dgLocation.AllowUserToAddRows = false;
            dgLocation.ReadOnly = true;

            dgAlarm.ColumnHeadersDefaultCellStyle.Font = new Font("微软雅黑", 12F, System.Drawing.FontStyle.Bold);
            dgAlarm.DefaultCellStyle.Font = new Font("微软雅黑", 12F, System.Drawing.FontStyle.Bold);
            dgAlarm.AllowUserToAddRows = false;
            dgAlarm.ReadOnly = true;

            dgDevS.ColumnHeadersDefaultCellStyle.Font = new Font("微软雅黑", 12F, System.Drawing.FontStyle.Bold);
            dgDevS.DefaultCellStyle.Font = new Font("微软雅黑", 12F, System.Drawing.FontStyle.Bold);
            dgDevS.AllowUserToAddRows = false;
            dgDevS.ReadOnly = true;

            dgSinal.ColumnHeadersDefaultCellStyle.Font = new Font("微软雅黑", 12F, System.Drawing.FontStyle.Bold);
            dgSinal.DefaultCellStyle.Font = new Font("微软雅黑", 12F, System.Drawing.FontStyle.Bold);
            dgSinal.AllowUserToAddRows = false;
            dgSinal.ReadOnly = true;
           
            runPl.Visible = true;

            sinalPl.Visible = false;
            veiclePl.Visible = false;
            trafficPl.Visible = false;
            logPl.Visible = false;
            userPl.Visible = false;

          

        }

       

        public MainForm(string userAccount, string passWord)
            : this()
        {
            userAcc = userAccount;
            passW = passWord;

            mainForm = this;       
            toolStripLabel3.Text = "青岛奇瑞"+"\n"+"前装";          
            mainManager = new MainManagerClass();


           
            #region 按钮事件初始化
            DeleteToolStripMenuItem.Click += mainManager.DeleteToolStripMenuItem_Click;

            AddToolStripMenuItem.Click += mainManager.AddToolStripMenuItem_Click;


            UpdateToolStripMenuItem.Click += mainManager.UpdateToolStripMenuItem_Click;

            tpMonitor.MouseDown += mainManager.tpMonitor_MouseDown;

            ToolStripMenuItemAdd.Click += mainManager.ToolStripMenuItemAdd_Click;
            dgSinal.CellContentClick += mainManager.DgSinal_CellContentClick;

            button35.Click+= mainManager.button35_Click;
            button36.Click += mainManager.button36_Click;


            button37.Click += mainManager.button37_Click;
            button38.Click += mainManager.button38_Click;
            //ToolStripMenuItemTrafficEdit.Click += mainManager.ToolStripMenuItemTrafficEdit_Click;
            //ChargeToolStripMenuItem.Click += mainManager.agv1ToolStripMenuItem_Click;
            ////agv2ToolStripMenuItem1.Click += mainManager.agv2ToolStripMenuItem1_Click;
            ////agv3ToolStripMenuItem2.Click += mainManager.agv3ToolStripMenuItem2_Click;
            ////agv4ToolStripMenuItem3.Click += mainManager.agv4ToolStripMenuItem3_Click;
            //aGV1ToolStripMenuItem.Click += mainManager.agv5ToolStripMenuItem4_Click;
            //ToolStripMenuItemCommunicateMsg.Click += mainManager.ToolStripMenuItemCommunicateMsg_Click;//
            //SendToolStripMenuItem.Click += mainManager.SendToolStripMenuItem_Click;
            //RecordSearchToolStripMenuItem.Click += mainManager.RecordSearchToolStripMenuItem_Click;
            //RunStateToolStripMenuItem.Click += mainManager.RunStateToolStripMenuItem_Click;
            //ToolStripMenuItemSystemMsg.Click += mainManager.ToolStripMenuItemSystemMsg_Click;
            //SetToolStripMenuItem.Click += mainManager.SetToolStripMenuItem_Click;
            //DispatchToolStripMenuItem.Click += mainManager.SendToolStripMenuItem_Click;
            //NumToolStripMenuItem.Click += mainManager.ToolStripMenuItemCommunicateMsg_Click;//
            //aGVa2ToolStripMenuItem1.Click += mainManager.ToolStripMenuItemTrafficEdit_Click;
            //aGVa3ToolStripMenuItem2.Click += mainManager.toolStripMenuItem1_Click;
            //oKAGV9TaskResetToolStripMenuItem5.Click += mainManager.toolStripMenuItem13_Click;
            //oKAGV8TaskResetToolStripMenuItem4.Click += mainManager.toolStripMenuItem14_Click;
            //oKAGV10TaskResetToolStripMenuItem6.Click += mainManager.toolStripMenuItem15_Click;
            //oKAGV4TaskResetToolStripMenuItem.Click += mainManager.toolStripMenuItem16_Click;
            //oKAGV5TaskResetToolStripMenuItem1.Click += mainManager.toolStripMenuItem17_Click;
            //oKAGV6TaskResetToolStripMenuItem2.Click += mainManager.toolStripMenuItem18_Click;
            //oKAGV7TaskResetToolStripMenuItem3.Click += mainManager.toolStripMenuItem19_Click;
            //oKAGV11TaskResetToolStripMenuItem7.Click += mainManager.toolStripMenuItem20_Click;
            ////FindToolStripMenuItem.Click += mainManager.FindToolStripMenuItem_Click;
            //WriteToolStripMenuItem.Click += mainManager.WriteToolStripMenuItem_Click;
            ////OFFToolStripMenuItem.Click += mainManager.OFFToolStripMenuItem_Click;
            //toolStripMenuItem4.Click += mainManager.toolStripMenuItem4_Click;
            //toolStripMenuItemSelect.Click += mainManager.toolStripMenuItemSelect_Click;
            //tpMonitor.MouseDown += mainManager.tpMonitor_MouseDown;
            //ToolStripMenuItemAdd.Click += mainManager.ToolStripMenuItemAdd_Click;
            //ToolStripMenuItemDelSingle.Click += mainManager.ToolStripMenuItemDelSingle_Click;
            //ToolStripMenuItemHid.Click += mainManager.ToolStripMenuItemHid_Click;

            //ConButton1.Click += mainManager.ConButton1_Click;
            //LeftYToolStripMenuItem.Click += mainManager.LeftYToolStripMenuItem_Click;
            //LeftNToolStripMenuItem.Click += mainManager.LeftNToolStripMenuItem_Click;
            //RightYToolStripMenuItem.Click += mainManager.RightYToolStripMenuItem_Click;
            //RightNToolStripMenuItem1.Click += mainManager.RightNToolStripMenuItem_Click;
            //AGVToolStripMenuItem.Click += mainManager.AGVToolStripMenuItem_Click;
            //toolStripMenuItem2.Click += mainManager.AGVToolStripMenuItems_Click;
            //StartRunToolStripMenuItem.Click += mainManager.StartRunToolStripMenuItem_Click;
            //ToolStripMenuItemTrafficEdit.Click += mainManager.StartRunToolStripMenuItems_Click;

            //NeitoolStripMenuItem4.Click += mainManager.NeitoolStripMenuItem4_Click;
            //NeitoolStripMenuItem13.Click += mainManager.NeitoolStripMenuItem13_Click;
            //NeitoolStripMenuItem14.Click += mainManager.NeitoolStripMenuItem14_Click;
            //NeitoolStripMenuItem15.Click += mainManager.NeitoolStripMenuItem15_Click;

            //doorToolStripMenuItem.Click += mainManager.doorToolStripMenuItem_Click;

            //lUpToolStripMenuItem.Click += mainManager.lUpToolStripMenuItem_Click;
            //lDownToolStripMenuItem.Click += mainManager.lDownToolStripMenuItem_Click;

            ////COkAGVToolStripMenuItem.Click += mainManager.toolDispatch92ok_Click;

            ////DuanAGVToolStripMenuItem.Click += mainManager.toolDispatch92ok1_Click;

            //toolStripButton1.Click += mainManager.toolStripButton1_Click;
            //toolStripButton3.Click += mainManager.toolStripButton3_Click;
            //toolStripButton2.Click += mainManager.toolStripButton2_Click;
            ////toolDisPatch.Click += mainManager.toolDispatch_Click;
            //disToolStripMenuItem.Click += mainManager.toolDispatch_Click;

            //toolStripMenuItem12.Click += mainManager.toolDispatchs_Click;

            //Sh90ToolStripMenuItem.Click += mainManager.toolDispatch90sh_Click;
            //su90ToolStripMenuItem.Click += mainManager.toolDispatch90su_Click;
            //sh91ToolStripMenuItem1.Click += mainManager.toolDispatch91sh_Click;
            //su91ToolStripMenuItem.Click += mainManager.toolDispatch91su_Click;
            //sh92ToolStripMenuItem2.Click += mainManager.toolDispatch92sh_Click;
            //su92ToolStripMenuItem1.Click += mainManager.toolDispatch92su_Click;

            //re90ToolStripMenuItem1.Click += mainManager.toolDispatch90re_Click;
            //re91ToolStripMenuItem2.Click += mainManager.toolDispatch91re_Click;
            //re92ToolStripMenuItem3.Click += mainManager.toolDispatch92re_Click;
            //LeiErToolStripMenuItem.Click += mainManager.toolDispatch92su_Click;

            //resetToolStripMenuItem.Click += mainManager.resetToolStripMenuItem_Click;

            //lastUpToolStripMenuItem.Click += mainManager.lastUpToolStripMenuItem_Click;

            //lastDownToolStripMenuItem.Click += mainManager.lastDownToolStripMenuItem_Click;

            //JigouToolStripMenuItem.Click += mainManager.JigouToolStripMenuItem_Click;

            //Jigou1ToolStripMenuItem.Click += mainManager.Jigou1ToolStripMenuItem_Click;

            //plcAgvToolStripMenuItem.Click += mainManager.plcAgvToolStripMenuItem_Click;
            #endregion

            #region 定时器初始化
            tmTime = new System.Windows.Forms.Timer();
            tmTime.Interval = 1000;
            tmTime.Tick += mainManager.tmTime_Tick;
            tmTime.Start();

            tmTrafficRecord = new System.Windows.Forms.Timer();
            tmTrafficRecord.Interval = 1000;
            tmTrafficRecord.Tick += mainManager.tmTrafficRecord_Tick;
            //tmTrafficRecord.Enabled = true;

            tmTaskShow = new System.Windows.Forms.Timer();
            tmTaskShow.Interval = 15000;
            tmTaskShow.Tick += mainManager.tmTaskShow_Tick;
            tmTaskShow.Start();

            tmOffine = new System.Windows.Forms.Timer();
            tmOffine.Interval = 3000;
            tmOffine.Tick += mainManager.tmOffine_Tick;
            //tmOffine.Start();

            tmPlc = new System.Windows.Forms.Timer();
            tmPlc.Interval = 2000;
            tmPlc.Tick += mainManager.tmPlc_Tick;
            tmPlc.Start();

            tmOkAgv = new System.Windows.Forms.Timer();
            tmOkAgv.Interval = 1000;
            tmOkAgv.Tick += mainManager.tmOkAgv_Tick;
            tmOkAgv.Start();



            //for (int i = 1; i < 34; i++)
            //{
            //    int index = dgState.Rows.Add();
            //    if (i == 1)
            //    {
            //        dgState.Rows[index].Cells[0].Value = "LCV1-PLC呼叫";
            //        dgState.Rows[index].Cells[1].Value = Properties.Resources.gray;
            //    }
            //    else if (i == 2)
            //    {
            //        dgState.Rows[index].Cells[0].Value = "LCV1-AGV请求下料";
            //        dgState.Rows[index].Cells[1].Value = Properties.Resources.gray;
            //    }
            //    else if (i == 3)
            //    {
            //        dgState.Rows[index].Cells[0].Value = "LCV1-PLC请求反馈";
            //        dgState.Rows[index].Cells[1].Value = Properties.Resources.gray;
            //    }
            //    else if (i == 4)
            //    {
            //        dgState.Rows[index].Cells[0].Value = "LCV1-PLC完成反馈";
            //        dgState.Rows[index].Cells[1].Value = Properties.Resources.gray;
            //    }
            //    else if (i == 5)
            //    {
            //        dgState.Rows[index].Cells[0].Value = "MCV1-PLC呼叫";
            //        dgState.Rows[index].Cells[1].Value = Properties.Resources.gray;
            //    }
            //    else if (i == 6)
            //    {
            //        dgState.Rows[index].Cells[0].Value = "MCV1-AGV请求下料";
            //        dgState.Rows[index].Cells[1].Value = Properties.Resources.gray;
            //    }
            //    else if (i == 7)
            //    {
            //        dgState.Rows[index].Cells[0].Value = "MCV1-PLC请求反馈";
            //        dgState.Rows[index].Cells[1].Value = Properties.Resources.gray;
            //    }
            //    else if (i == 8)
            //    {
            //        dgState.Rows[index].Cells[0].Value = "MCV1-PLC完成反馈";
            //        dgState.Rows[index].Cells[1].Value = Properties.Resources.gray;
            //    }
            //    else if (i == 9)
            //    {
            //        dgState.Rows[index].Cells[0].Value = "RCV1-PLC呼叫";
            //        dgState.Rows[index].Cells[1].Value = Properties.Resources.gray;
            //    }
            //    else if (i == 10)
            //    {
            //        dgState.Rows[index].Cells[0].Value = "RCV1-AGV请求下料";
            //        dgState.Rows[index].Cells[1].Value = Properties.Resources.gray;
            //    }
            //    else if (i == 11)
            //    {
            //        dgState.Rows[index].Cells[0].Value = "RCV1-PLC请求反馈";
            //        dgState.Rows[index].Cells[1].Value = Properties.Resources.gray;
            //    }
            //    else if (i == 12)
            //    {
            //        dgState.Rows[index].Cells[0].Value = "RCV1-PLC完成反馈";
            //        dgState.Rows[index].Cells[1].Value = Properties.Resources.gray;
            //    }
            //    else if (i == 13)
            //    {
            //        dgState.Rows[index].Cells[0].Value = "LCV47-AGV请求上料";
            //        dgState.Rows[index].Cells[1].Value = Properties.Resources.gray;
            //    }
            //    else if (i == 14)
            //    {
            //        dgState.Rows[index].Cells[0].Value = "LCV47-AGV完成上料";
            //        dgState.Rows[index].Cells[1].Value = Properties.Resources.gray;
            //    }
            //    else if (i == 15)
            //    {
            //        dgState.Rows[index].Cells[0].Value = "LCV47-PLC反馈";
            //        dgState.Rows[index].Cells[1].Value = Properties.Resources.gray;
            //    }
            //    else if (i == 16)
            //    {
            //        dgState.Rows[index].Cells[0].Value = "MCV48-AGV请求上料";
            //        dgState.Rows[index].Cells[1].Value = Properties.Resources.gray;
            //    }
            //    else if (i == 17)
            //    {
            //        dgState.Rows[index].Cells[0].Value = "MCV48-AGV完成上料";
            //        dgState.Rows[index].Cells[1].Value = Properties.Resources.gray;
            //    }
            //    else if (i == 18)
            //    {
            //        dgState.Rows[index].Cells[0].Value = "MCV48-PLC反馈";
            //        dgState.Rows[index].Cells[1].Value = Properties.Resources.gray;
            //    }
            //    else if (i == 19)
            //    {
            //        dgState.Rows[index].Cells[0].Value = "RCV48-AGV请求上料";
            //        dgState.Rows[index].Cells[1].Value = Properties.Resources.gray;
            //    }
            //    else if (i == 20)
            //    {
            //        dgState.Rows[index].Cells[0].Value = "RCV48-AGV完成上料";
            //        dgState.Rows[index].Cells[1].Value = Properties.Resources.gray;
            //    }
            //    else if (i == 21)
            //    {
            //        dgState.Rows[index].Cells[0].Value = "RCV48-PLC反馈";
            //        dgState.Rows[index].Cells[1].Value = Properties.Resources.gray;
            //    }
            //    else if (i == 22)
            //    {
            //        dgState.Rows[index].Cells[0].Value = "90充电桩伸出";
            //        dgState.Rows[index].Cells[1].Value = Properties.Resources.gray;
            //    }
            //    else if (i == 23)
            //    {
            //        dgState.Rows[index].Cells[0].Value = "90充电桩缩回";
            //        dgState.Rows[index].Cells[1].Value = Properties.Resources.gray;
            //    }
            //    else if (i == 24)
            //    {
            //        dgState.Rows[index].Cells[0].Value = "90充电桩前限位";
            //        dgState.Rows[index].Cells[1].Value = Properties.Resources.gray;
            //    }
            //    else if (i == 25)
            //    {
            //        dgState.Rows[index].Cells[0].Value = "90充电桩后限位";
            //        dgState.Rows[index].Cells[1].Value = Properties.Resources.gray;
            //    }
            //    else if (i == 26)
            //    {
            //        dgState.Rows[index].Cells[0].Value = "91充电桩伸出";
            //        dgState.Rows[index].Cells[1].Value = Properties.Resources.gray;
            //    }
            //    else if (i == 27)
            //    {
            //        dgState.Rows[index].Cells[0].Value = "91充电桩缩回";
            //        dgState.Rows[index].Cells[1].Value = Properties.Resources.gray;
            //    }
            //    else if (i == 28)
            //    {
            //        dgState.Rows[index].Cells[0].Value = "91充电桩前限位";
            //        dgState.Rows[index].Cells[1].Value = Properties.Resources.gray;
            //    }
            //    else if (i == 29)
            //    {
            //        dgState.Rows[index].Cells[0].Value = "91充电桩后限位";
            //        dgState.Rows[index].Cells[1].Value = Properties.Resources.gray;
            //    }
            //    else if (i == 30)
            //    {
            //        dgState.Rows[index].Cells[0].Value = "92充电桩伸出";
            //        dgState.Rows[index].Cells[1].Value = Properties.Resources.gray;
            //    }
            //    else if (i == 31)
            //    {
            //        dgState.Rows[index].Cells[0].Value = "92充电桩缩回";
            //        dgState.Rows[index].Cells[1].Value = Properties.Resources.gray;
            //    }
            //    else if (i == 32)
            //    {
            //        dgState.Rows[index].Cells[0].Value = "92充电桩前限位";
            //        dgState.Rows[index].Cells[1].Value = Properties.Resources.gray;
            //    }
            //    else if (i == 33)
            //    {
            //        dgState.Rows[index].Cells[0].Value = "92充电桩后限位";
            //        dgState.Rows[index].Cells[1].Value = Properties.Resources.gray;
            //    }
            //}






            //for (int i = 1; i < 8; i++)
            //{
            //    int index = dgTask.Rows.Add();
            //    if (i == 1)
            //    {
            //        dgTask.Rows[index].Cells[0].Value = "AGV等待进入信号";
            //        dgTask.Rows[index].Cells[1].Value = Properties.Resources.gray;
            //    }
            //    else if (i == 2)
            //    {
            //        dgTask.Rows[index].Cells[0].Value = "AGV到位信号";
            //        dgTask.Rows[index].Cells[1].Value = Properties.Resources.gray;
            //    }
            //    else if (i == 3)
            //    {
            //        dgTask.Rows[index].Cells[0].Value = "AGV离开信号(有车)";
            //        dgTask.Rows[index].Cells[1].Value = Properties.Resources.gray;
            //    }
            //    else if (i == 4)
            //    {
            //        dgTask.Rows[index].Cells[0].Value = "AGV离开信号(无车)";
            //        dgTask.Rows[index].Cells[1].Value = Properties.Resources.gray;
            //    }
            //    else if (i == 5)
            //    {
            //        dgTask.Rows[index].Cells[0].Value = "门上升到位信号";
            //        dgTask.Rows[index].Cells[1].Value = Properties.Resources.gray;
            //    }
            //    else if (i == 6)
            //    {
            //        dgTask.Rows[index].Cells[0].Value = "机械夹具上升到位信号";
            //        dgTask.Rows[index].Cells[1].Value = Properties.Resources.gray;
            //    }
            //    else if (i == 7)
            //    {
            //        dgTask.Rows[index].Cells[0].Value = "键检测信号";
            //        dgTask.Rows[index].Cells[1].Value = Properties.Resources.gray;
            //    }

            //}
            #endregion

          
            timer1.Start();
        }

        private void DeleteToolStripMenuItem_Click(object sender, EventArgs e)
        {
            throw new NotImplementedException();
        }

        private void MainForm_Load(object sender, EventArgs e)
        {
            this.WindowState = FormWindowState.Maximized;

            toolStripLabel2.BackgroundImage = Properties.Resources.logo;

            runBt.Image = Properties.Resources.monitor_64;

            sinalBt.Image = Properties.Resources.statistics_64;

            vechleBt.Image = Properties.Resources.flag_64;

            trafficBt.Image = Properties.Resources.plus_64 ;

            logBt.Image = Properties.Resources.search_64;

            toolStripButton5.Image = Properties.Resources.user_64;

            tpMonitor.BackgroundImage = Properties.Resources.bg;
        }

        private void MainForm_FormClosed(object sender, FormClosedEventArgs e)
        {
           
        }

        private void toolStripTextBox1_MouseDown(object sender, MouseEventArgs e)
        {
            //toolStripTextBox1.Text = "";
        }

        private void toolStripTextBox2_MouseDown(object sender, MouseEventArgs e)
        {
            //toolStripTextBox2.Text = "";
        }

        private void toolStripTextBox3_MouseDown(object sender, MouseEventArgs e)
        {
            //toolStripTextBox3.Text = "";
        }

        private void dgAgvInfo_Scroll(object sender, ScrollEventArgs e)
        {
            if (e.ScrollOrientation == ScrollOrientation.VerticalScroll)
            {
                AgvFunctionClass.VerticalScrollIndex = e.NewValue;
            }
            else if (e.ScrollOrientation == ScrollOrientation.HorizontalScroll)
            {
                AgvFunctionClass.HorizontalOffset = e.NewValue;
            }
        }

        private void dgCheck_Scroll(object sender, ScrollEventArgs e)
        {
            if (e.ScrollOrientation == ScrollOrientation.VerticalScroll)
            {
                AgvFunctionClass.VerticalScrollIndex1 = e.NewValue;
            }
            else if (e.ScrollOrientation == ScrollOrientation.HorizontalScroll)
            {
                AgvFunctionClass.HorizontalOffset1 = e.NewValue;
            }
        }


        #region 内存回收
        [DllImport("kernel32.dll", EntryPoint = "SetProcessWorkingSetSize")]
        public static extern int SetProcessWorkingSetSize(IntPtr process, int minSize, int maxSize);
        /// <summary>
        /// 释放内存
        /// </summary>
        public static void ClearMemory()
        {
            GC.Collect();
            GC.WaitForPendingFinalizers();
            if (Environment.OSVersion.Platform == PlatformID.Win32NT)
            {
                SetProcessWorkingSetSize(System.Diagnostics.Process.GetCurrentProcess().Handle, -1, -1);
            }
        }
        #endregion


        private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            try
            {
                DialogResult Result = MessageBox.Show("是否退出系统？！！", "警告", MessageBoxButtons.OKCancel);
                if (Result == DialogResult.OK)
                {
                    Dispose();
                    Application.Exit();
                }
                else
                {
                    e.Cancel = true;
                }
            }
            catch
            { }

        }

        private void dgState_Scroll(object sender, ScrollEventArgs e)
        {
            if (e.ScrollOrientation == ScrollOrientation.VerticalScroll)
            {
                AgvFunctionClass.VerticalScrollIndex2 = e.NewValue;
            }
            else if (e.ScrollOrientation == ScrollOrientation.HorizontalScroll)
            {
                AgvFunctionClass.HorizontalOffset2 = e.NewValue;
            }
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            try
            {
                ClearMemory();
               // label12.Text = AgvFunctionClass.IsStartTraffic.ToString();          
            }
            catch
            { }          
        }

        private void runBt_Click(object sender, EventArgs e)
        {
            runPl.Visible = true;
            sinalPl.Visible = false;
            veiclePl.Visible = false;
            trafficPl.Visible = false;
            logPl.Visible = false;
            userPl.Visible = false;
        }

        private void sinalBt_Click(object sender, EventArgs e)
        {
            runPl.Visible = false;
            sinalPl.Visible = true;
            veiclePl.Visible = false;
            trafficPl.Visible = false;
            logPl.Visible = false;
            userPl.Visible = false;
        }

        private void vechleBt_Click(object sender, EventArgs e)
        {
            mode = 1;
            runPl.Visible = false;
            sinalPl.Visible = false;
            veiclePl.Visible = true;
            trafficPl.Visible = false;
            logPl.Visible = false;
            userPl.Visible = false;

            comboBox2.Items.Clear();
            comboBox2.Items.Add("仪表线");
            comboBox2.Items.Add("车门线");
            comboBox2.Items.Add("发变分装线");
            comboBox2.Items.Add("动总分装线");
            comboBox2.Items.Add("后轴分装线");
            comboBox2.Items.Add("前滑柱分装线");          
            comboBox2.Items.Add("SPS");
            comboBox2.SelectedIndex = 0;

            if (dgLine.Rows.Count == 0)
            {
                mainManager.amf = new AgvManageForm(1,null);
                mainManager.amf.AddEvent += mainManager.amf_AddEvent;
                mainManager.amf.ShowDialog();
            }          
        }

        private void trafficBt_Click(object sender, EventArgs e)
        {
           
        }

        private void logBt_Click(object sender, EventArgs e)
        {
          
        }

        private void toolStripButton5_Click(object sender, EventArgs e)
        {
            runPl.Visible = false;

            sinalPl.Visible = false;
            veiclePl.Visible = false;
            trafficPl.Visible = false;
            logPl.Visible = false;
            userPl.Visible = true;
        }

        private void AreaToolStripMenuItem_Click(object sender, EventArgs e)
        {
            mode = 2;

            runPl.Visible = false;

            sinalPl.Visible = false;
            veiclePl.Visible = false;
            trafficPl.Visible = true;
            logPl.Visible = false;
            userPl.Visible = false;

            panel1.Visible = false;
            panel2.Visible = true;
            panel2.Dock = DockStyle.Fill;


            if (dgTraffic.Rows.Count == 0)
            {
                mainManager.tmf = new TrafficManageForm(1, null);
                mainManager.tmf.AddEvent += mainManager.tmf_AddEvent;
                mainManager.tmf.ShowDialog();
            }
        }

        private void ResetToolStripMenuItem_Click(object sender, EventArgs e)
        {
            runPl.Visible = false;

            sinalPl.Visible = false;
            veiclePl.Visible = false;
            trafficPl.Visible = true;
            logPl.Visible = false;
            userPl.Visible = false;

            panel1.Visible = true;
            panel2.Visible = false;
            panel1.Dock = DockStyle.Fill;
        }

        public int selectIndexDgTraffic = 100;
        public int selectIndexDgLine = 100;
        public static int mode = 0;
        private void dgTraffic_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            try
            {
                if (e.Button == MouseButtons.Right)
                {
                    if (e.RowIndex > -1)
                    {


                        selectIndexDgTraffic = e.RowIndex;

                        //contextMenuStrip1.Items[1].Visible = false;
                        contextMenuStrip1.Show(Cursor.Position);

                        this.dgTraffic.Rows[e.RowIndex].DefaultCellStyle.ForeColor = Color.Lime;

                        for (int i = 0; i < dgTraffic.Rows.Count; i++)
                        {
                            if (i != e.RowIndex)
                                this.dgTraffic.Rows[i].DefaultCellStyle.ForeColor = Color.White;
                        }


                    }
                }
            }
            catch
            { }
        }

        private void dgLine_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            try
            {
                if (e.Button == MouseButtons.Right)
                {
                    if (e.RowIndex > -1)
                    {


                        selectIndexDgLine = e.RowIndex;

                        contextMenuStrip1.Show(Cursor.Position);

                        this.dgLine.Rows[e.RowIndex].DefaultCellStyle.ForeColor = Color.Lime;

                        for (int i = 0; i < dgLine.Rows.Count; i++)
                        {
                            if (i != e.RowIndex)
                                this.dgLine.Rows[i].DefaultCellStyle.ForeColor = Color.White;
                        }


                    }
                }
            }
            catch
            { }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            try
            {
                MainManagerClass.plcMDic[int.Parse(textBox2.Text)].StartAgv();
            }
            catch
            {
                MessageBox.Show("请输入AGV编号");
            }
        }

        private void button4_Click(object sender, EventArgs e)
        {
            try
            {
                MainManagerClass.plcMDic[int.Parse(textBox2.Text)].StopAgv();
            }
            catch
            {
                MessageBox.Show("请输入AGV编号");
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            try
            {
                MainManagerClass.plcMDic[int.Parse(textBox2.Text)].LockAgv();
            }
            catch
            {
                MessageBox.Show("请输入AGV编号");
            }
        }

        private void button5_Click(object sender, EventArgs e)
        {
            try
            {
                MainManagerClass.plcMDic[int.Parse(textBox2.Text)].UnLockAgv();
            }
            catch
            {
                MessageBox.Show("请输入AGV编号");
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                TrafficManagerClass.ClearTrafficArea(int.Parse(textBox1.Text));
            }
            catch
            {
                MessageBox.Show("复位异常");
            }
          
        }

        private void ReadLogToolStripMenuItem_Click(object sender, EventArgs e)
        {
            runPl.Visible = false;

            sinalPl.Visible = false;
            veiclePl.Visible = false;
            trafficPl.Visible = false;
            logPl.Visible = true;
            userPl.Visible = false;

            panel4.Visible = true;
            panel5.Visible = false;
            panel6.Visible = false;
            panel7.Visible = false;
            panel4.Dock = DockStyle.Fill;


            try
            {

                //dgCardRecord.Rows.Clear();
                //cardExports.Clear();
                if (AgvFunctionClass.stationRecordList.Count > 0)
                {
                    dgStation26.DataSource = null;
                    dgStation26.DataSource = AgvFunctionClass.stationRecordList;
                }
            }
            catch
            { MessageBox.Show("获取数据失败"); }





        }

        private void button6_Click(object sender, EventArgs e)
        {
            try
            {
                //dgCardRecord.Rows.Clear();
                //cardExports.Clear();
                List<AgvStationClass> ascList = new List<AgvStationClass>();
                if (AgvFunctionClass.stationRecordList.Count > 0)
                {
                    for (int i = 0; i < AgvFunctionClass.stationRecordList.Count; i++)
                    {
                        if (AgvFunctionClass.stationRecordList[i].AgvNum.ToString() == textBox3.Text)
                        {
                            ascList.Add(AgvFunctionClass.stationRecordList[i]);
                        }


                    }


                    dgStation26.DataSource = null;
                    dgStation26.DataSource = ascList;
                }
            }
            catch
            { MessageBox.Show("获取数据失败"); }

        }

        private void CommandToolStripMenuItem_Click(object sender, EventArgs e)
        {
            runPl.Visible = false;

            sinalPl.Visible = false;
            veiclePl.Visible = false;
            trafficPl.Visible = false;
            logPl.Visible = true;
            userPl.Visible = false;

            panel4.Visible = false;
            panel5.Visible = true;
            panel6.Visible = false;
            panel7.Visible = false;
            panel5.Dock = DockStyle.Fill;



            try
            {
                //dgCommand.Rows.Clear();
                //cmdExports.Clear();
                if (AgvFunctionClass.commandList.Count > 0)
                {

                    dgCommand26.DataSource = null;
                    dgCommand26.DataSource = AgvFunctionClass.commandList;

                }
            }
            catch
            { MessageBox.Show("获取数据失败"); }

        }

   
        private void button7_Click(object sender, EventArgs e)
        {
            try
            {
                //dgCommand.Rows.Clear();
                //cmdExports.Clear();
                List<AgvCommandClass> accTemp = new List<AgvCommandClass>();
                if (AgvFunctionClass.commandList.Count > 0)
                {
                    for (int i = 0; i < AgvFunctionClass.commandList.Count; i++)
                    {
                        if (AgvFunctionClass.commandList[i].AgvNum.ToString() == textBox4.Text)
                        {
                            accTemp.Add(AgvFunctionClass.commandList[i]);
                        }


                    }


                    dgCommand26.DataSource = null;
                    dgCommand26.DataSource = accTemp;
                }
            }
            catch
            { MessageBox.Show("获取数据失败"); }
        }

        private void button8_Click(object sender, EventArgs e)
        {
            try
            {
                //dgCardRecord.Rows.Clear();
                //cardExports.Clear();
                List<AgvStationClass> ascList = new List<AgvStationClass>();
                if (AgvFunctionClass.stationRecordList.Count > 0)
                {
                    for (int i = 0; i < AgvFunctionClass.stationRecordList.Count; i++)
                    {
                        if (AgvFunctionClass.stationRecordList[i].Station.ToString() == textBox5.Text)
                        {
                            ascList.Add(AgvFunctionClass.stationRecordList[i]);
                        }


                    }

                    dgStation26.DataSource = null;
                    dgStation26.DataSource = ascList;
                }
            }
            catch
            {
                MessageBox.Show("获取数据失败");
            }
        }

        private void button9_Click(object sender, EventArgs e)
        {
           
            try
            {
                DialogResult dr = MessageBox.Show("是否当前数据生成EXCEL报表？？？", "警告", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);

              
            }
            catch
            {

            }
        }

        private void button10_Click(object sender, EventArgs e)
        {
            try
            {
                DialogResult dr = MessageBox.Show("是否当前数据生成EXCEL报表？？？", "警告", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);

               
            }
            catch
            {

            }
        }

        private void FaultToolStripMenuItem_Click(object sender, EventArgs e)
        {
            runPl.Visible = false;

            sinalPl.Visible = false;
            veiclePl.Visible = false;
            trafficPl.Visible = false;
            logPl.Visible = true;
            userPl.Visible = false;

            panel4.Visible = false;
            panel5.Visible = false;
            panel6.Visible = true;
            panel7.Visible = false;
            panel6.Dock = DockStyle.Fill;

            comboBox1.Items.Clear();

            comboBox1.Items.Add("驱动升降错误");
            comboBox1.Items.Add("牵引升降错误");
            comboBox1.Items.Add("无路径错误");
            comboBox1.Items.Add("通信板超时");
            comboBox1.Items.Add("急停错误");
            comboBox1.Items.Add("防撞错误");
            comboBox1.Items.Add("驱动器故障");
            comboBox1.SelectedIndex = 0;

            try
            {
                // dgFault.Rows.Clear();
                //faultExports.Clear();

                MainManagerClass.faultRecordList = MainManagerClass.faultRecordBll.GetModelList("");
                List<FaultClass> fcList = new List<FaultClass>();
                if (MainManagerClass.faultRecordList.Count > 0)
                {
                    for (int i = 0; i < MainManagerClass.faultRecordList.Count; i++)
                    {
                        FaultClass fc = new FaultClass();
                        fc.No = "AGV" + MainManagerClass.faultRecordList[i].agv_num;
                        fc.Station = MainManagerClass.faultRecordList[i].occur_station.ToString();

                        if (MainManagerClass.faultRecordList[i].fault_code == 1)
                        { fc.Fault = "驱动升降错误"; }
                        else if (MainManagerClass.faultRecordList[i].fault_code == 2)
                        { fc.Fault = "牵引升降错误"; }
                        else if (MainManagerClass.faultRecordList[i].fault_code == 4)
                        { fc.Fault = "无路径错误"; }
                        else if (MainManagerClass.faultRecordList[i].fault_code == 8)
                        { fc.Fault = "通信板超时"; }
                        else if (MainManagerClass.faultRecordList[i].fault_code == 16)
                        { fc.Fault = "急停错误"; }
                        else if (MainManagerClass.faultRecordList[i].fault_code == 32)
                        { fc.Fault = "防撞错误"; }
                        else if (MainManagerClass.faultRecordList[i].fault_code == 64)
                        { fc.Fault = "驱动器故障"; }
                        //MainForm.mainForm.dgAgvInfo.Rows[index].Cells[2].Value = "/";

                        fc.Time = MainManagerClass.faultRecordList[i].occur_time.ToString();
                        fcList.Add(fc);


                    }


                    dgFault26.DataSource = null;
                    dgFault26.DataSource = fcList;
                }
            }
            catch
            {
                MessageBox.Show("获取数据库数据失败");
            }



        }

        private void button13_Click(object sender, EventArgs e)
        {
            try
            {
                //dgFault.Rows.Clear();
                //faultExports.Clear();
                MainManagerClass.faultRecordList = MainManagerClass.faultRecordBll.GetModelList("agv_num=" + int.Parse(textBox7.Text) + "");
                List<FaultClass> fcList = new List<FaultClass>();
                if (MainManagerClass.faultRecordList.Count > 0)
                {
                    for (int i = 0; i < MainManagerClass.faultRecordList.Count; i++)
                    {
                        FaultClass fc = new FaultClass();
                        fc.No = "AGV" + MainManagerClass.faultRecordList[i].agv_num;
                        fc.Station = MainManagerClass.faultRecordList[i].occur_station.ToString();

                        if (MainManagerClass.faultRecordList[i].fault_code == 1)
                        { fc.Fault = "驱动升降错误"; }
                        else if (MainManagerClass.faultRecordList[i].fault_code == 2)
                        { fc.Fault = "牵引升降错误"; }
                        else if (MainManagerClass.faultRecordList[i].fault_code == 4)
                        { fc.Fault = "无路径错误"; }
                        else if (MainManagerClass.faultRecordList[i].fault_code == 8)
                        { fc.Fault = "通信板超时"; }
                        else if (MainManagerClass.faultRecordList[i].fault_code == 16)
                        { fc.Fault = "急停错误"; }
                        else if (MainManagerClass.faultRecordList[i].fault_code == 32)
                        { fc.Fault = "防撞错误"; }
                        else if (MainManagerClass.faultRecordList[i].fault_code == 64)
                        { fc.Fault = "驱动器故障"; }
                        //MainForm.mainForm.dgAgvInfo.Rows[index].Cells[2].Value = "/";

                        fc.Time = MainManagerClass.faultRecordList[i].occur_time.ToString();
                        fcList.Add(fc);


                    }


                    dgFault26.DataSource = null;
                    dgFault26.DataSource = fcList;
                }
            }
            catch
            { MessageBox.Show("获取数据库数据失败"); }

        }

        private void button12_Click(object sender, EventArgs e)
        {
            try
            {
                //dgFault.Rows.Clear();
                //faultExports.Clear();
                if (comboBox1.SelectedIndex == 0)
                {
                    MainManagerClass.faultRecordList = MainManagerClass.faultRecordBll.GetModelList("fault_code = 1");
                }
                else if (comboBox1.SelectedIndex == 1)
                {
                    MainManagerClass.faultRecordList = MainManagerClass.faultRecordBll.GetModelList("fault_code = 2");
                }
                else if (comboBox1.SelectedIndex == 2)
                {
                    MainManagerClass.faultRecordList = MainManagerClass.faultRecordBll.GetModelList("fault_code = 4");
                }
                else if (comboBox1.SelectedIndex == 3)
                {
                    MainManagerClass.faultRecordList = MainManagerClass.faultRecordBll.GetModelList("fault_code = 8");
                }
                else if (comboBox1.SelectedIndex == 4)
                {
                    MainManagerClass.faultRecordList = MainManagerClass.faultRecordBll.GetModelList("fault_code = 16");
                }
                else if (comboBox1.SelectedIndex == 5)
                {
                    MainManagerClass.faultRecordList = MainManagerClass.faultRecordBll.GetModelList("fault_code = 32");
                }
                else if (comboBox1.SelectedIndex == 6)
                {
                    MainManagerClass.faultRecordList = MainManagerClass.faultRecordBll.GetModelList("fault_code = 64");
                }
                List<FaultClass> fcList = new List<FaultClass>();

                if (MainManagerClass.faultRecordList.Count > 0)
                {
                    for (int i = 0; i < MainManagerClass.faultRecordList.Count; i++)
                    {
                        FaultClass fc = new FaultClass();
                        fc.No = "AGV" + MainManagerClass.faultRecordList[i].agv_num;
                        fc.Station = MainManagerClass.faultRecordList[i].occur_station.ToString();

                        if (MainManagerClass.faultRecordList[i].fault_code == 1)
                        { fc.Fault = "驱动升降错误"; }
                        else if (MainManagerClass.faultRecordList[i].fault_code == 2)
                        { fc.Fault = "牵引升降错误"; }
                        else if (MainManagerClass.faultRecordList[i].fault_code == 4)
                        { fc.Fault = "无路径错误"; }
                        else if (MainManagerClass.faultRecordList[i].fault_code == 8)
                        { fc.Fault = "通信板超时"; }
                        else if (MainManagerClass.faultRecordList[i].fault_code == 16)
                        { fc.Fault = "急停错误"; }
                        else if (MainManagerClass.faultRecordList[i].fault_code == 32)
                        { fc.Fault = "防撞错误"; }
                        else if (MainManagerClass.faultRecordList[i].fault_code == 64)
                        { fc.Fault = "驱动器故障"; }
                        //MainForm.mainForm.dgAgvInfo.Rows[index].Cells[2].Value = "/";

                        fc.Time = MainManagerClass.faultRecordList[i].occur_time.ToString();
                        fcList.Add(fc);


                    }


                    dgFault26.DataSource = null;
                    dgFault26.DataSource = fcList;
                }
            }
            catch
            { MessageBox.Show("获取数据库数据失败"); }
        }

        private void button11_Click(object sender, EventArgs e)
        {
            try
            {
                DialogResult dr = MessageBox.Show("是否当前数据生成EXCEL报表？？？", "警告", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);

              
            }
            catch
            {

            }
        }

        private void button15_Click(object sender, EventArgs e)
        {
            //AgvLocationClss alc = new AgvLocationClss();
            //alc.serno = DateTime.Now.ToString("yyyyMMddHHmmss") + AgvFunctionClass.GetRandomNumberOther(100000, 999999);
            //alc.eqp_num = "dev1";
            //alc.station = "10";
            //alc.vin = "test001";
            //alc.time = DateTime.Now.ToString("yyyyMMdd HH:mm:ss");

            //string postData= JsonConvert.SerializeObject(alc);
            //textBox6.Text= PostToServer.Post("http://10.2.5.170:8113/web/httpServlet/api/agvReportEquipmentChangedStation", postData);
        }

        private void button14_Click(object sender, EventArgs e)
        {
            //AgvAlarmClass aac = new AgvAlarmClass();
            //aac.serno = DateTime.Now.ToString("yyyyMMddHHmmss") + AgvFunctionClass.GetRandomNumberOther(100000, 999999);
            //aac.eqp_num = "dev1";
            //aac.alarm_status = "发生";
            //aac.alarm_type = "低";
            //aac.alarm_code = "4";
            //aac.alarm_msg = "无路径错误";

            //aac.alarm_time = DateTime.Now.ToString("yyyyMMdd HH:mm:ss");

            //string postData = JsonConvert.SerializeObject(aac);
            //textBox6.Text = PostToServer.Post("http://10.2.5.170:8113/web/httpServlet/api/agvReportEquipmentAlarm", postData);
        }

        private void button17_Click(object sender, EventArgs e)
        {
            try
            {
                DialogResult dr = MessageBox.Show("是否复位？？？", "警告", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);

                if (dr == DialogResult.OK)
                {
                    AgvFunctionClass.TrafficSureDic[1] = 0;
                }
            }
            catch
            {

            }
        }

        private void button16_Click(object sender, EventArgs e)
        {
            try
            {
                DialogResult dr = MessageBox.Show("是否关闭？？？", "警告", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);

                if (dr == DialogResult.OK)
                {
                    AgvFunctionClass.IsStartTraffic = false;

                    MessageBox.Show("关闭成功");
                }
            }
            catch
            {

            }
        }

        private void iOTAGVToolStripMenuItem_Click(object sender, EventArgs e)
        {
            runPl.Visible = false;

            sinalPl.Visible = false;
            veiclePl.Visible = false;
            trafficPl.Visible = false;
            logPl.Visible = true;
            userPl.Visible = false;

            panel4.Visible = false;
            panel5.Visible = false;
            panel6.Visible = false;
            panel7.Visible = true;
            panel7.Dock = DockStyle.Fill;
            tabControl1.SelectedTabIndex = 0;

            try
            {
                dgFang.Rows.Clear();
                dgLocation.Rows.Clear();
                dgAlarm.Rows.Clear();
                dgDevS.Rows.Clear();
              

             
            }
            catch
            { MessageBox.Show("获取数据失败"); }
        }

    

        #region iot放行
        private void button21_Click(object sender, EventArgs e)
        {
            try
            {
               
            }
            catch
            { }
          
        }

        private void button20_Click(object sender, EventArgs e)
        {
            try
            {
               
            }
            catch
            { MessageBox.Show("获取数据失败"); }
        }

        private void button19_Click(object sender, EventArgs e)
        {
            try
            {
            
            }
            catch
            { MessageBox.Show("获取数据失败"); }
        }

        private void button18_Click(object sender, EventArgs e)
        {
            try
            {
              
            }
            catch
            {

            }
        }
        #endregion

        #region agv位置
        private void button22_Click(object sender, EventArgs e)
        {
      
          
        }

        private void button25_Click(object sender, EventArgs e)
        {
          
           
        }

        private void button24_Click(object sender, EventArgs e)
        {
            
         
        }

        private void button23_Click(object sender, EventArgs e)
        {
         
        }
        #endregion

        #region agv报警
        private void button26_Click(object sender, EventArgs e)
        {
            try
            {
               
            }
            catch
            { }
          
        }

        private void button29_Click(object sender, EventArgs e)
        {
            try
            {
              
            }
            catch
            { }
           
        }

        private void button28_Click(object sender, EventArgs e)
        {
            try
            {
            
            }
            catch
            { }
        
        }

        private void button27_Click(object sender, EventArgs e)
        {
          
        }
        #endregion

        #region iot查询
        private void button30_Click(object sender, EventArgs e)
        {
         
        }

        private void button33_Click(object sender, EventArgs e)
        {
         
          
        }

        private void button31_Click(object sender, EventArgs e)
        {
           
        }
        #endregion

        private void button32_Click(object sender, EventArgs e)
        {
            try
            {
                dgLine.Rows.Clear();
                int tempNum = 0;
                if (comboBox2.SelectedIndex == 0)
                {
                    tempNum = 3;
                }
                else if (comboBox2.SelectedIndex == 1)
                {
                    tempNum = 4;
                }
                else if (comboBox2.SelectedIndex == 2)
                {
                    tempNum = 2;
                }
                else if (comboBox2.SelectedIndex == 3)
                {
                    tempNum = 7;
                }
                else if (comboBox2.SelectedIndex == 4)
                {
                    tempNum = 6;
                }
                else if (comboBox2.SelectedIndex == 5)
                {
                    tempNum = 5;
                }
                else if (comboBox2.SelectedIndex == 6)
                {
                    tempNum = 1;
                }

                for (int i = 0; i < MainManagerClass.agvDeviceList.Count; i++)
                {
                    if (MainManagerClass.agvDeviceList[i].agv_workline == tempNum)
                    {
                        int index = dgLine.Rows.Add();
                        dgLine.Rows[index].ReadOnly = true;
                        dgLine.Rows[index].Cells[0].Value = MainManagerClass.agvDeviceList[i].agv_id;
                        dgLine.Rows[index].Cells[1].Value = MainManagerClass.agvDeviceList[i].agv_ip;
                        if (MainManagerClass.agvDeviceList[i].agv_workline == 1)
                        {
                            dgLine.Rows[index].Cells[2].Value = "SPS";
                            dgLine.Rows[index].DefaultCellStyle.ForeColor = Color.White;
                        }

                        else if (MainManagerClass.agvDeviceList[i].agv_workline == 2)
                        {
                            dgLine.Rows[index].Cells[2].Value = "发变分装线";
                            dgLine.Rows[index].DefaultCellStyle.ForeColor = Color.White;
                        }
                        else if (MainManagerClass.agvDeviceList[i].agv_workline == 3)
                        {
                            dgLine.Rows[index].Cells[2].Value = "仪表线";
                            dgLine.Rows[index].DefaultCellStyle.ForeColor = Color.White;
                        }
                        else if (MainManagerClass.agvDeviceList[i].agv_workline == 4)
                        {
                            dgLine.Rows[index].Cells[2].Value = "车门线";
                            dgLine.Rows[index].DefaultCellStyle.ForeColor = Color.White;
                        }
                        else if (MainManagerClass.agvDeviceList[i].agv_workline == 5)
                        {
                            dgLine.Rows[index].Cells[2].Value = "前滑柱分装线";
                            dgLine.Rows[index].DefaultCellStyle.ForeColor = Color.White;
                        }
                        else if (MainManagerClass.agvDeviceList[i].agv_workline == 6)
                        {
                            dgLine.Rows[index].Cells[2].Value = "后轴分装线";
                            dgLine.Rows[index].DefaultCellStyle.ForeColor = Color.White;
                        }
                        else if (MainManagerClass.agvDeviceList[i].agv_workline == 7)
                        {
                            dgLine.Rows[index].Cells[2].Value = "动总分装线";
                            dgLine.Rows[index].DefaultCellStyle.ForeColor = Color.White;
                        }
                    }
                }
            }
            catch
            { }
        }

        private void button34_Click(object sender, EventArgs e)
        {
            try
            { 
                dgLine.Rows.Clear();
                mainManager.BindAgv(); 
            }
            catch
            { }
        }
    }


  

    public class FaultClass
    {

        public string No { get; set; }

        public string Station { get; set; }
        public string Fault { get; set; }
        public string Time { get; set; }

    }
    
}